<!DOCTYPE html>

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JWIM - Js Windowmanager for Independent Modules</title>

<link rel="stylesheet" href="./JWIM_API_Reference_files/default.css" type="text/css">
</head>

<body>
<div id="top"><img src="./JWIM_API_Reference_files/jwim_logo.png"></div>
<div id="menu">
	<ul>
		<li class="active"><a href="#">API REFERENCE</a></li>
	</ul>
</div>
<div id="submenu">
<ul>
	<li><a href="#manager">jwim.Manager class</a></li>
	<li><a href="#window">jwim.Window class</a></li>
</ul>
</div>

<a name="manager"></a>
<div class="reftitle">class jwim.Manager</div>
<div class="refcont">
	<p>Instantiate class jwim.Manager used to create and manage modules</p>
	<h3>Constructor</h3>
	<table>
	<tbody><tr><th>Constructor</th><th>Description</th>
	</tr><tr><td>jwim.Manager(options?:object)</td><td>Returns handle to window manager</td></tr>
	</tbody></table>
	
	<h3>Options</h3>
	<p>This optional parameter is used to customize the window manager behaviour</p>
	<table>
	<tbody><tr><th>Property</th><th>Type</th><th>Default</th><th>Description</th>
	
	</tr><tr><td>classWindow</td><td>STRING</td><td>JMWindow</td><td>Class name for window</td></tr>
	<tr><td>classActiveWindow</td><td>STRING</td><td>activeJMWindow</td><td>Class name for active window</td></tr>
	<tr><td>classContent</td><td>STRING</td><td>content</td><td>Class name for content div. Margins are not allowed, use padding instead</td></tr>
	<tr><td>classTitle</td><td>STRING</td><td>title</td><td>Class name for titlebar div</td></tr>
	<tr><td>classIcon</td><td>STRING</td><td> JMIcon</td><td>Class name for icon div</td></tr>
	<tr><td>classActiveIcon</td><td>STRING</td><td> activeJMIcon</td><td>Class name for active icon</td></tr>
	<tr><td>imageDir</td><td>STRING</td><td> img/jwim</td><td>Path to image folder</td></tr>
	<tr><td>baseZIndex</td><td>NUMBER</td><td>5000</td><td>Starting z-index</td></tr>
	<tr><td>alwaysShowIcons</td><td>BOOL</td><td>true</td><td>If false icons on taskbar are created only when the window is iconized</td></tr>
	<tr><td>taskbar</td><td>HTMLELEMENT</td><td>NULL</td><td>Taskbar container </td></tr>
	<tr><td>container</td><td>HTMLELEMENT</td><td>document.body</td><td>Element where windows are attached</td></tr>
	<tr><td>showTitleBar</td><td>BOOLEAN</td><td>true</td><td>Sets the visualization of the titlebar</td></tr>
	<tr><td>showIconImage</td><td>BOOLEAN</td><td>true</td><td>Sets the visualization of the icon image</td></tr>
	<tr><td>showMaximizer</td><td>BOOLEAN</td><td>true</td><td>Sets the visualization of maximizer button</td></tr>
	<tr><td>showIconizer</td><td>BOOLEAN</td><td>true</td><td>Sets the visualization of iconizer button</td></tr>
	<tr><td>showResizer</td><td>BOOLEAN</td><td>true</td><td>Sets the visualization of the resizer</td></tr>
	<tr><td>showClose</td><td>BOOLEAN</td><td>true</td><td>Sets the visualization of close button</td></tr>
	
	<tr><td>defaultX</td><td>NUMBER</td><td>10</td><td>Default window's x coordinate</td></tr>
	<tr><td>defaultY</td><td>NUMBER</td><td>10</td><td>Default window's y coordinate</td></tr>
	<tr><td>defaultWidth</td><td>NUMBER</td><td>500</td><td>Default window's width</td></tr>
	<tr><td>defaultHeight</td><td>NUMBER</td><td>350</td><td>Default window's height</td></tr>
	<tr><td>defaultState</td><td>STRING</td><td>window</td><td>Default window's state</td></tr>
	<tr><td>buttonSize</td><td>NUMBER</td><td>16</td><td>Size of window buttons in pixel.</td></tr>

	
	<tr><td>movable</td><td>BOOLEAN</td><td>true</td><td>Sets the ability of move window</td></tr>
	<tr><td>shiftOffset</td><td>NUMBER</td><td>20</td><td>Sets the number of pixels used to shift window if created over an existing one</td></tr>
	<tr><td>bottomMargin</td><td>NUMBER</td><td>16</td><td>Distance in pixel between the content and the bottom side of the window</td></tr>
	<tr><td>iconWidth</td><td>NUMBER</td><td>100</td><td>Width in pixel of the icons</td></tr>
	<tr><td>resizeIcons</td><td>BOOLEAN</td><td>true</td><td>If this options is set the icons are automatically resized to fit the taskbar width</td></tr>
	<tr><td>autoCheckResize</td><td>BOOLEAN</td><td>true</td><td>If this options is set jwim will automatically add a document.onresize event handler to adjust the size of maximized windows and, if necessary, icons</td></tr>
	<tr><td>containerBoundaries</td><td>NUMBER</td><td>40</td><td>If greater than zero windows cannot be moved outside the container
	and remain visible for the specified amount of pixels. If set to 0 only the top boundary , which is always 0, is
	used. If set to -1 no boundaries are used.</td></tr>

 	<tr>
 		<td>cacheXHR</td>
 		<td>BOOLEAN</td>
 		<td>FALSE</td>
 		<td>If set to false a timestamp is automatically added at the end of urls passed to loadUrl method
 		to prevent XHR request from being cached.</td>
 	</tr>
 	
 	<tr>
 		<td>httpErrorHandler: function(xhr,url,win)</td>
 		<td>FUNCTION</td>
 		<td>NULL</td>
 		<td>Default function to handle http errors. The XHR object, the url that genereted the error and 
 		the window where the error occurred are passed as parameters.<br>
		If this option is not set an alert box is used to report the error.</td>
 	</tr>
 	<tr>
 		<td>afterLoad: function(win)</td>
 		<td>FUNCTION</td>
 		<td>NULL</td>
 		<td>This function is called when a new window content is loaded. It can be used to initialize 
 			variables, functions and events of the target module without using modules's script
 		</td>
 	</tr> 	
	</tbody></table>
	
	
	
	
	<h3>Methods</h3>
	<table>
	<tbody><tr><th>Method</th><th width="5%">Return Value</th><th>Description</th>
	</tr><tr>
		<td>createWindow(options?:object)</td>
		<td> jwim.Window</td>
		<td>Creates a new Window. If successful the new window is returned otherwise null.<br>
		The option object is described below.
		</td>
	</tr>
	<tr>
		<td>getWindow(id)</td>
		<td> jwim.Window</td>
		<td>Returns the Window with the corrisponding id.</td>
	</tr>	
	<tr>
		<td>getSelectedWindow()</td>
		<td> jwim.Window</td>
		<td>Seturns the selected window if one, otherwise null is returned</td>
	</tr>
	<tr>
		<td>getAllWindows()</td>
		<td>ARRAY</td>
		<td>Returns an array of all windows. The topmost window is at index zero. </td>
	</tr>

	<tr>
		<td>getContainerWidth()</td>
		<td> NUMBER</td>
		<td>Returns the width in pixel of the window's container.</td>
	</tr>
	<tr>
		<td>getContainerHeight()</td>
		<td> NUMBER</td>
		<td>Returns the height in pixel of the window's container.</td>
	</tr>
	<tr>
		<td>checkResize()</td>
		<td> NONE</td>
		<td>This method is used to adjust the size of maximized windows and, if necessary, icons</td>
	</tr>
	</tbody></table>
	
	
</div>


<a name="window"></a>
<div class="reftitle">class jwim.Window</div>
<div class="refcont">
	<h3>Constructor</h3>
	<p>Class jwim.Window has no contructor and it is instantiate by the createWindow method.</p>

	<h3>Options</h3>
	<p>This object is the optional parameter of the createWindow method.</p>
	<table>
	<tbody><tr><th>Property</th>	<th>Type</th>	<th>Default</th>	<th>Description</th>
	
	</tr><tr><td>id</td><td>STRING</td><td><i>generated</i></td><td>Id of the window</td></tr>
	<tr><td>width</td><td>NUMBER</td><td><i>inherit</i></td><td>Window's width</td></tr>
	<tr><td>height</td><td>NUMBER</td><td><i>inherit</i></td><td>Window's height</td></tr>
	<tr><td>x</td><td>NUMBER</td><td><i>inherit</i></td><td>Window's X position</td></tr>
	<tr><td>y</td><td>NUMBER</td><td><i>inherit</i></td><td>Window's Y position</td></tr>
	<tr><td>centered</td><td>BOOLEAN</td><td><i>false</i></td><td>Setting this value to true makes the window at container's center</td></tr>
	<tr><td>title</td><td>STRING</td><td><i>none</i></td><td>Window's title</td></tr>
	<tr><td>iconImageURL</td><td>STRING</td><td><i>none</i></td><td>URL of the icon image on title bar and task bar</td></tr>
	<tr><td>movable</td><td>BOOLEAN</td><td><i>inherit</i></td><td>Setting this value to true allows the window to be moved</td></tr>
	<tr><td>alwaysOnTop</td><td>BOOLEAN</td><td>false</td><td>Setting this value to true makes the window always on top</td></tr>
	<tr><td>state</td><td>STRING</td><td><i>inherit</i></td><td>Window's initial state. States are <b>window</b>, <b>maximized</b>, <b>icon</b></td></tr>
	<tr><td>container</td><td>HTMLELEMENT</td><td><i>inherit</i></td><td>Window's container</td></tr>
	 	<tr>
 		<td>afterLoad: function(win)</td>
 		<td>FUNCTION</td>
 		<td><i>inherit</i></td>
 		<td>This function is called when a new window content is loaded.</td>
 	</tr> 
	</tbody></table>
			
	
	
	<h3>Methods</h3>
	<table>
	<tbody><tr><th>Method</th><th width="5%">Return Value</th><th>Description</th>
	</tr><tr>
		<td>setContent(content:string,element?:htmlelement)</td>
		<td> NONE</td>
		<td>Loads a content into window. Content can contain both html and javascripts, if javascripts are present
		they are loaded in the scope of the window. <br>
		The optional parameter <i>element</i> is used to specify the html element 
		to load the content into, if omitted the whole window is used. <br>
		When content is loaded the convertElementAttributes method is automatically called against
		<i>element</i></td>
	</tr>
	<tr>
		<td>loadUrl(url:string,onload?:function(thisw),onerror?:function(thisw))</td>
		<td> NONE</td>
		<td>
			Downloads a content and passes it to setContent. The onload function, if present, will be called
			after the new content is set. The onerror function, if present, will be called when some error occured.
		</td>
	</tr>
	<tr>
		<td>loadUrlX(url:string,onload?:function(thisw))</td>
		<td> NONE</td>
		<td>
			Downloads a content from cross-domain server. The onload function, if present, will be called
			after the new content is set.
		</td>
	</tr>
	
	<tr>
		<td>convertElementsAttributes(element:htmlelement)</td>
		<td> NONE</td>
		<td>This method is used to let event attributes to see the <b>thisw</b> object and to convert A tags so  urls
		are loaded inside the window. It crawls the <i>element</i>'s tree and applies the conversions; to prevent A tags 
		from being converted the TARGET attribute must be set.</td>
	</tr>
	<tr>
		<td>getElement(id:string)</td>
		<td> HTMLELEMENT</td>
		<td>Returns the element inside the window with the <b>data-wid</b> attribute equal to <i>id</i>. It behaves like
		document.getElementById but sice its search is limited to elements inside the window, different windows can have the same
		data-wid attribute.</td>
	</tr>
	<tr>
		<td>attachTo(container:htmlelement)</td>
		<td> NONE</td>
		<td>
			Attach the current window to container. If container is null the window will be attached to the 
			one specified in manager's options.
	</td></tr>
	<tr>
		<td>getContainer()</td>
		<td> HTMLELEMENT</td>
		<td>Returns the container of the window</td>
	</tr>

	<tr>
		<td>getContainerWidth()</td>
		<td>NUMBER</td>
		<td>Returns the window's container width in pixel</td>
	</tr>

	<tr>
		<td>getContainerHeight()</td>
		<td>NUMBER</td>
		<td>Returns the window's container height in pixel</td>
	</tr>
	<tr>
		<td>setTitle(title:string)</td>
		<td>NONE</td>
		<td>Sets the title of the window.</td>
	</tr>
	<tr>
		<td>setIconImage(url:string)</td>
		<td>NONE</td>
		<td>Sets the icon image URL of the window.</td>
	</tr>
	<tr>
		<td>setState(state:string)</td>
		<td>NONE</td>
		<td>Sets the state of the window and fires the corresponding event. States are <b>window</b>, <b>maximized</b>, <b>icon</b>.</td>
	</tr>
	<tr>
		<td>setMovable(state:boolean)</td>
		<td> NONE</td>
		<td>Sets the ability to move window</td>
	</tr>	
	<tr>
		<td>setSize(width:number,height:number)</td>
		<td> NONE</td>
		<td>Sets width and height of the window in pixel and fires the <b>onresize</b> event.</td>
	</tr>
	<tr>
		<td>setPosition(x:number,x:number)</td>
		<td> NONE</td>
		<td>Sets the x and y coordinates of the window in pixel and fires the <b>onmove</b> event.</td>
	</tr>
	
	<tr>
		<td>moveToCenter()</td>
		<td> NONE</td>
		<td>Move the window to container's center and fires the <b>onmove</b> event.</td>
	</tr>

	<tr>
		<td>setAlwaysOnTop(value:boolean)</td>
		<td> NONE</td>
		<td>Sets the always-on-top flag. If it's true window is also selected and events are triggered.</td>
	</tr>

	<tr>
		<td>select()</td>
		<td> NONE</td>
		<td>Selects current window and fires the <b>onselect</b> event. If window is iconized it will be restored.</td>
	</tr>
	<tr>
		<td>close()</td>
		<td> NONE</td>
		<td>Closes the window and fires the <b>onclose</b> event.</td>
	</tr>
	<tr>
		<td>showLoading(show:?boolean)</td>
		<td> NONE</td>
		<td>Shows the loading indicator. If show is false the indicator is hidden .</td>
	</tr>
	<tr>
		<td>isMovable()</td>
		<td> BOOLEAN</td>
		<td>Returns true if the window is movable.</td>
	</tr>
	<tr>
		<td>isSelected()</td>
		<td> BOOLEAN</td>
		<td>Returns true if the window is selected.</td>
	</tr>
	<tr>
		<td>isAlwaysOnTop()</td>
		<td> BOOLEAN</td>
		<td>Returns true if the window is always-on-top.</td>
	</tr>	

	<tr>
		<td>getWidth()</td>
		<td> NUMBER</td>
		<td>Returns the width of the window in pixel</td>
	</tr>
	<tr>
		<td>getHeight()</td>
		<td> NUMBER</td>
		<td>Returns the height of the window in pixel</td>
	</tr>
	<tr>
		<td>getContentWidth()</td>
		<td> NUMBER</td>
		<td>Returns the width in pixel of the area where content is displayed</td>
	</tr>
	<tr>
		<td>getContentHeight()</td>
		<td> NUMBER</td>
		<td>Returns the height in pixel of the area where content is displayed</td>
	</tr>	
	<tr>
		<td>getX()</td>
		<td> NUMBER</td>
		<td>Returns the X coordinate of the window in pixel</td>
	</tr>
	<tr>
		<td>getY()</td>
		<td> NUMBER</td>
		<td>Returns the Y coordinate of the window in pixel</td>
	</tr>

	<tr>
		<td>getId()</td>
		<td> STRING</td>
		<td>Returns the ID of the window</td>
	</tr>
	<tr>
		<td>getTitle()</td>
		<td> STRING</td>
		<td>Returns the title of the window</td>
	</tr>
	<tr>
		<td>getCurrentUrl(full:?boolean)</td>
		<td> STRING</td>
		<td>Returns the current URL of the window if one otherwise null.
		If the optional parameter full is true and jwim.Manager is configured to prevent XHR caching
		the url is returned with the timestamp at the end.</td>
	</tr>

	<tr>
		<td>getState()</td>
		<td> STRING</td>
		<td>Returns the state of the window.</td>
	</tr>
	<tr>
		<td>getComponent(component:string)</td>
		<td> HTMLELEMENT</td>
		<td>Returns the reference to the given component. Components are titlebar, content, window, resizer, close, iconizer, maximizer, icon, loading and iconImage.</td>
	</tr>	
	<tr>
		<td>getManager()</td>
		<td> jwim.Manager</td>
		<td>Returns a reference to the window manager that instantiated the window.</td>
	</tr>
	
	</tbody></table>
	
	
	<h3>Events</h3>
	<p>Window events are related to loaded content so they are cleared when new content is loaded</p>
	<table>
	<tbody><tr><th>Event</th><th>Description</th>
	</tr><tr>
		<td>onselect()</td>
		<td>This event is fired when the window is selected.</td>
	</tr>	
	<tr>
		<td>ondeselect()</td>
		<td>This event is fired when the window is deselected.</td>
	</tr>		
	<tr>
		<td>onmove(x:number, y:number)</td>
		<td>This event is fired when the window is moved. The <i>x</i> and <i>y</i> parameters specify the
		current window's coordinates.</td>
	</tr>
	<tr>
		<td>onresize(width:number,&nbsp;height:number, action:string)</td>
		<td>This event is fired when the window is resized. The <i>width</i> and <i>height</i> parameters specify the
		current window's size. Action specifies what fired the event, it could be <i>resize </i>,<i> maximize</i> or <i>restore </i>.</td>
	</tr>
	<tr>
		<td>oniconize()</td>
		<td>This event is fired when the window is iconized.</td>
	</tr>

	<tr>
		<td>onunload()</td>
		<td>This event is fired before a new content is loaded (ie loadUrl method) or before the window is closed.
		The event handler can return false to abort the operation.
		</td>
	</tr>
	
	<tr>
		<td>onclose()</td>
		<td>This event is fired after the window is closed.
		</td>
	</tr>	
	<tr>
		<td>onhttperror(xhr,&nbsp;url)</td>
		<td>This event is fired on http error and overrides the default http error handler.
		</td>
	</tr>
	</tbody></table>
</div>

<div id="footer">
<hr>
last update: 2012-02-20. Contact authors: poplix@papuasia.org, allidylls@gmail.com
</div>
</body></html>
